# Group Topics

You aren't limited to just Feed based MQTT topics, Adafruit IO supports grouped feeds as well.  [Similar to our HTTP group data creation API](https://io.adafruit.com/api/docs/#operation/createGroupData), you can publish to multiple feeds or subscribe to multiple feeds through a single MQTT topic.

The topics formats for publishing or subscribing are:

-   `(username)/groups/(group name or key)`
-   `(username)/groups/(group name or key)/json`
-   `(username)/groups/(group name or key)/csv`

### Publish to Feeds in a Group

If you use the `/json` or `/csv` endings on your group MQTT topic, your data should be formatted in JSON or CSV, respectively. By default, IO expects published values to be in JSON format.

The JSON and CSV format IO expects are displayed below:

JSON Expected Response from Adafruit IO

<% partial 'helpers/inline_code' do %>
```json
{
  "feeds": {
    "key-1": "value 1",
    "key-2": "value 2",
    "key-3": "value 3"
  },
  "location": {
    "lat": 0.0,
    "lon": 0.0,
    "ele": 0.0
  }
}
```
<% end %>

CSV Format Expected Response from Adafruit IO

<% partial 'helpers/inline_code' do %>
```csv
key-1,value 1
key-2,value 2
key-3,value 3
location,0.0,0.0,0.0
```
<% end %>


## Group Guidelines

-   In each payload format, `key-1` represents the respective feed's key and `value 1` represents the value you'd like to publish to that feed.
-   For CSV location values, the location is interpreted as `lat`, `lon`, `ele` and `ele` is optional `/` not required.
-   Any number of feeds present in the group may be included.
-   Each value may be either a string or a number.
-   If any feed key is included that does not already belong to a feed in the group, then a new feed with the given key as its name will be created.

### Subscribing to groups

If you use the `/json` or `/csv` endings when subscribing to your group MQTT topic, your data will be formatted in JSON or CSV, respectively. By default, IO publishes values in JSON format.

The formats your subscription will receive are the same as the formats IO expects to receive. Expected responses for JSON and CSV are below.

Expected Group JSON Response

<% partial 'helpers/inline_code' do %>
```json
{
  "feeds": {
    "key-1": "value 1",
    "key-2": "value 2",
    "key-3": "value 3"
  },
  "location": {
    "lat": 1.0,
    "lon": 2.0,
    "ele": 3.0
  }
}
```
<% end %>

Expected Group CSV Response

<% partial 'helpers/inline_code' do %>
```csv
key-1,value 1
key-2,value 2
key-3,value 3
location,1.0,2.0,3.0
```
<% end %>

It's important to note that you will only receive updated values for the feeds that received new values. That means if you're subscribed to  `{username}/groups/example`  and publish to  `{username}/feeds/key-1`, the subscription will receive:

<% partial 'helpers/inline_code' do %>
```json
{
  "feeds": {
    "key-1": "value 1"
  }
}
```
<% end %>

It's also worth noting that JSON subscription formats will always receive string type values, regardless of whether a string or number was published.
